<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <ui:composition template="/modelo/padrao.xhtml">
        <ui:define name="conteudo">
            <p:panel id="panel" header="Cadastrar Proprietário">
                <h:form id="form_proprietario">
                    <h:inputHidden id="ih_id" value="#{proprietarioBean.proprietario.id}"/>

                    <f:metadata>
                        <f:viewParam name="CADASTRAR_PROPRIETARIO" value="#{proprietarioBean.enviadoDaSolicitacao}"/>
                    </f:metadata>

                    <h:panelGrid columns="3">
                        <label for="it_nome">Nome:</label>
                        <p:inputText id="it_nome" 
                                     value="#{proprietarioBean.proprietario.nome}" 
                                     size="40"
                                     required="true"
                                     requiredMessage="Campo Obrigatório"/>
                        <p:message id="msg_nome" for="it_nome" />

                        <label for="it_email">Email:</label>
                        <p:inputText id="it_email" 
                                     size="40"
                                     value="#{proprietarioBean.proprietario.email}"/>
                        <p:message id="msg_email" for="it_email"/>

                        <label for="im_telefone">Telefone:</label>
                        <p:inputText id="im_telefone" 
                                     value="#{proprietarioBean.proprietario.telefone}" 
                                     size="15"
                                     maxlength="15"
                                     required="true"
                                     requiredMessage="Campo Obrigatório"/>
                        <p:message id="msg_telefone" for="im_telefone"/>

                        <label for="som_local">Local:</label>
                        <p:selectOneMenu id="som_local"
                                         value="#{proprietarioBean.proprietario.local}"
                                         var="local"
                                         required="true"
                                         requiredMessage="Campo Obrigatório"
                                         converter="localConverter">
                            <f:selectItem itemLabel="Selecione" noSelectionOption="true"/>
                            <f:selectItems value="#{localBean.locais}"
                                           var="l"
                                           itemLabel="#{l.municipio}"
                                           itemValue="#{l}"/>

                            <p:column>
                                <span>#{local.municipio}</span>
                            </p:column>

                            <p:column>
                                <span>#{local.estado}</span>
                            </p:column>
                        </p:selectOneMenu>
                        <p:message id="msg_local" for="som_local"/>
                    </h:panelGrid>
                        
                    <p>
                        <p:commandButton id="cb_salvar" 
                                         ajax="false"
                                         value="Salvar"
                                         action="#{proprietarioBean.salvar()}"/>
                        <p:button id="bt_cancelar" 
                                  value="Cancelar" 
                                  outcome="lista_proprietario"/>
                    </p>
                </h:form>
            </p:panel>
        </ui:define>
    </ui:composition>
</html>